#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/11/30 10:41
# @Author  : lizhen
# @Site    : 
# @File    : cSimpleServer.py
# @Software: PyCharm
from threading import Thread
from flask import Flask, request


class SimpleServerDemo:
    app = Flask(__name__)
    dic = {
        4000: 1,
        4001: 2,
        4002: 3
    }

    def task(self, port):
        @self.app.route('/', endpoint=str(port))
        def hello_world():
            port = int(request.host.split(':')[-1])
            return '<h1>hello world2018_{}</h1>'.format(self.dic[port])

        self.app.run(host='0.0.0.0', port=port)

    def _test_task(self):
        """
        ssd = SimpleServerDemo()
        ssd._test_task()
        >
        192.168.99.80:4000
        192.168.99.80:4001
        192.168.99.80:4002
        """
        for key in self.dic:
            t = Thread(target=self.task, args=(key,))
            t.start()


if __name__ == '__main__':
    ssd = SimpleServerDemo()
    ssd._test_task()
